package leetcode;

/**
 * 7. 整数反转
 * @author yujiafan
 * @version 1.0.0
 * @create 2022-12-13
 */
public class LeetCode7 {

    public static int reverse(int x) {
        if(x == 0) return x;
        int result = 0;
        boolean flag = false;
        if(x < 0) {
            x = -x;
            flag = true;
        }
        while(x > 0 && x % 10 == 0){
            x = x / 10;
        }
        while (x > 0){
            if (result>214748364 || (result==214748364 && x % 10 >= 6)) {
                return 0;
            }
            result = result * 10 + x % 10;
            x = x / 10;
        }
        return flag ? -result : result;
    }

    public static void main(String[] args) {
        System.out.println(reverse(1534236469));
    }
}
